//
//  MXFoodPlanListCell.m
//  HNBaseProject
//
//  Created by xujie on 2024/6/4.
//

#import "MXFoodPlanListCell.h"

@implementation MXFoodPlanListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createUI];
    }
    return self;
}

- (void)createUI {
    self.selectionStyle = 0;
    self.backgroundColor = [UIColor whiteColor];
    
    self.timeLab = [[UILabel alloc] init];
//    self.timeLab.text = @"8:00";
    self.timeLab.textColor = [UIColor colorWithHexString:@"#000000"];
    self.timeLab.font = PFRFont(24);
    [self.contentView addSubview:self.timeLab];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(28);
        make.top.offset(26);
        make.height.mas_equalTo(18);
    }];
    
    self.countLab = [[UILabel alloc] init];
    [self.contentView addSubview:self.countLab];
    self.countLab.textColor = [UIColor colorWithHexString:@"#000000"];
    self.countLab.font = PFRFont(12);
//    self.countLab.text = @"3份";
    [self.countLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(29);
        make.top.mas_equalTo(self.timeLab.mas_bottom).offset(6);
    }];
    
    self.line = [[UIView alloc] init];
    self.line.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
    [self.contentView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(5);
        make.right.offset(-5);
        make.height.mas_equalTo(2);
        make.bottom.offset(0);
    }];
    
    self.switchBtn = [[UISwitch alloc] init];
    [self.switchBtn setOnTintColor:[UIColor colorWithHexString:@"#3278F6"]];
    [self.contentView addSubview:self.switchBtn];
    [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(35);
        make.height.mas_equalTo(20);
        make.centerY.mas_equalTo(self.contentView);
        make.right.offset(-40);
    }];
    //添加事件监听
    [self.switchBtn addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
}

- (void)switchAction:(UISwitch *)sender {
    if (self.valueBlock) {
        self.valueBlock(sender.on);
    }
}

- (void)reloadCellWithModel:(MXFooderPlanListModel *)model {
    if (model.planTime.length > 6) {
        NSString *planTime = [model.planTime substringToIndex:5];
        self.timeLab.text = planTime;
    } else {
        self.timeLab.text = model.planTime;
    }
   
    self.countLab.text = [NSString stringWithFormat:@"%@份",model.grainOuput];
    self.switchBtn.on = model.status;
}

@end
